/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package escr.clases;

/**
 *
 * @author Aditardo
 */
/*
 * GuardarDatos.java
 *
 * Created on 29 de junio de 2007, 12:20 AM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

/**
 *
 * @author USER_2007
 */
public class GuardarDatos {

    private static EntityManagerFactory emf = Persistence.createEntityManagerFactory("WebAdtafa_EcPU");
    
    /** Creates a new instance of GuardarDatos */
    public GuardarDatos() {
    }

    
    public void grabar(Object object) {
        EntityManager em = emf.createEntityManager();
        em.getTransaction().begin();
        try {
                em.merge(object);
                em.getTransaction().commit();            
             //  JOptionPane.showMessageDialog(null,"Sus datos han sido guardados correctamente","**GUARDADO...**",JOptionPane.PLAIN_MESSAGE);
        } catch (Exception e) {
            e.printStackTrace();
            em.getTransaction().rollback();
        } finally {
            em.close();
        }
    }
    
       public void ingreso(Object object) {
        EntityManager em = emf.createEntityManager();
        em.getTransaction().begin();
        try {
                em.merge(object);
                em.getTransaction().commit();            
              
        } catch (Exception e) {
            e.printStackTrace();
            em.getTransaction().rollback();
        } finally {
            em.close();
        }
    }
       
    public void modificar(Object object) {
        EntityManager em = emf.createEntityManager();
        em.getTransaction().begin();
        try {
                em.merge(object);
                em.getTransaction().commit();            
               
        } catch (Exception e) {
            e.printStackTrace();
            em.getTransaction().rollback();
        } finally {
            em.close();
        }
    }
    
     public void grabarFiltro(Object object) {
        EntityManager em = emf.createEntityManager();
        em.getTransaction().begin();
        try {
                em.merge(object);
                em.getTransaction().commit();                                            
        } catch (Exception e) {
            e.printStackTrace();
            em.getTransaction().rollback();
        } finally {
            em.close();
        }
    }
    
     
    public void persist(Object object) {
        EntityManager em = emf.createEntityManager();
        em.getTransaction().begin();
        try {
            // TODO:
            // em.persist(object);    em.getTransaction().commit();
        } catch (Exception e) {
            e.printStackTrace();
            em.getTransaction().rollback();
        } finally {
            em.close();
        }
    }
    
}
